package com.jyw.business.obstacles.websocket.config;

import com.jyw.business.obstacles.websocket.handler.ServerDeskHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * @author 沈峻
 * @ClassName WebSocketConfig
 * @Description TODO
 * @Date 2023/8/21 14:34
 **/
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer{

    @Resource
    private ServerDeskHandler serverDeskHandler;

    @Resource
    private MyInterceptor myInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry
                .addHandler(serverDeskHandler, "/server/desk")
                .addInterceptors(myInterceptor)
                .setAllowedOrigins("*");
    }
}
